#ifndef CONTROLS_H
#define CONTROLS_H

#define PICTURE_CONTROLNUMBER 16

class PictureControl;
class PictureButton;
class PictureList;
class ENumList;
class PictureDraggableImage;
class PictureImage;
class PictureMatrix;
class HSlider;

int InitControls(HWND hWnd);
int SetControlImages();

PictureControl *GetControl(int ID);

int ChangeTransform(PictureList *This);
int ChangeSize(PictureList *This);

int OnQMatrixChanged(PictureMatrix *This);

int Multi1xOnPressed(PictureButton *This);
int Multi2xOnPressed(PictureButton *This);
int Multi4xOnPressed(PictureButton *This);

int MultiplyMatrix(HSlider *This);

int Multi4xOnPressed(PictureButton *This);

int OpenCloseMatrix(PictureButton *This);

int Button1OnPressed(PictureButton *This);

int ToImageDblClick(PictureDraggableImage *This);

class ENumList
{
public:
	LPWSTR Value;
	int Len;
	ENumList *Next;
	ENumList(LPWSTR Value, int Len)
	{
		this->Next = NULL; this->Value = Value;
		this->Len = Len;
	}
	~ENumList()
	{
		if (this->Next) delete Next;
		this->Next = NULL;
		delete [] this->Value;
	}
};

#define DROP_DRAGGABLEIMAGE 1

class PictureControl
{
public:
	RECT Coordinates;
	HWND hWnd;
	void *p;
	int Shown;
	int Flags;
	int id;
	int NoChangeCoords;
	PictureControl *Next;
	PictureControl(RECT Coords, HWND hWnd);
	virtual int OnMouseLeftButtonDown(int x, int y);
	virtual int OnMouseMove(int x, int y);
	virtual int OnMouseLeftButtonUp(int x, int y);
//	virtual int OnMouseLeftButtonDblClick(int x, int y);
	virtual int OnDrop(PictureControl *Control, int type);
	virtual int Redraw(LPDIRECTDRAWSURFACE7 dest);
	virtual int Update();
	virtual int Release();
};

#define PICTBTN_IMAGE 0
#define PICTBTN_PRESSEDIMAGE 1

class PictureButton : public PictureControl
{
public:
	LPDIRECTDRAWSURFACE7 Image;
	LPDIRECTDRAWSURFACE7 ImageDown;
	LPDIRECTDRAWSURFACE7 CurrentImage;
	int Streched;
	int (*OnButtonPressed)(PictureButton *This);
	PictureButton(RECT Coords, HWND hWnd);
	~PictureButton();
	int SetImage(int ImageType, LPDIRECTDRAWSURFACE7 surf, int Copy);
	int OnMouseLeftButtonDown(int x, int y);
	int OnMouseLeftButtonUp(int x,int y);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
	int Release();
};

#define PCSDR_STRECHBACKGROUND 0x1
#define PICTSLDR_BIT 0
#define PICTSLDR_PRESSEDBIT 1

class VSlider : public PictureControl
{
public:
	LPDIRECTDRAWSURFACE7 Bit;
	LPDIRECTDRAWSURFACE7 PressedBit;
	LPDIRECTDRAWSURFACE7 CurrentBit;
	LPDIRECTDRAWSURFACE7 Background;
	int MaxValue;
	int Position;
	int BitHeight;
	int (*OnMove)(VSlider *This);
	VSlider(RECT Coords, HWND hWnd,
		int MaxValue, int OnButtonPressed(VSlider *This), int Flags);
	~VSlider();
	int SetImage(int Type, LPDIRECTDRAWSURFACE7 surf, int Copy);
	int OnMouseLeftButtonDown(int x, int y);
	int OnMouseMove(int x, int y);
	int OnMouseLeftButtonUp(int x, int y);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
	int Release();
};

class HSlider : public PictureControl
{
public:
	LPDIRECTDRAWSURFACE7 Bit;
	LPDIRECTDRAWSURFACE7 PressedBit;
	LPDIRECTDRAWSURFACE7 CurrentBit;
	LPDIRECTDRAWSURFACE7 Background;
	int MaxValue;
	int Position;
	int BitWidth;
	int (*OnMove)(HSlider *This);
	HSlider(RECT Coords, HWND hWnd, 
		int MaxValue, int OnButtonPressed(HSlider *This), int Flags);
	~HSlider();
	int SetImage(int Type, LPDIRECTDRAWSURFACE7 surf, int Copy);
	int OnMouseLeftButtonDown(int x, int y);
	int OnMouseMove(int x, int y);
	int OnMouseLeftButtonUp(int x, int y);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
	int Release();
};

#define PICTLIST_SELECTEDIMAGE 0x0	//xx0
#define PICTLIST_ACTIVEIMAGE 0x1	//xx1

#define PICTLIST_ALIGNLEFT 0x0		//00x
#define PICTLIST_ALIGNMIDDLE 0x2	//01x
#define PICTLIST_ALIGNRIGHT 0x4	//10x

class PictureList : public PictureControl
{
public:
	BitmapFont *font;
//	LPDIRECTDRAWSURFACE7 active;
	LPDIRECTDRAWSURFACE7 selected;
	ENumList *List;
	int NumElements;
	int ElementHeight;
	int FirstElement;
	int SelectedItem;
//	int ActiveItem;

// Text Options
	int LeftOffset;
	int RightOffset;

	LPDIRECTDRAWSURFACE7 background;
	int OnMouseLeftButtonDown(int x, int y);
//	int OnMouseLeftButtonDblClick(int x, int y);
	int AddElement(LPWSTR Value);
	int ClearList();
	PictureList(RECT Coords, HWND hWnd, LPDIRECTDRAWSURFACE7 back, 
		int OffSetLeft, int OffsetRight, int SelectedColor, int ElementHeight, 
		BitmapFont *font, int OnSetItem(PictureList *This), int Flags);
	int SetItemImage(int ItemType, LPDIRECTDRAWSURFACE7 surf, int Left, int Middle, int Right, int Copy);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
	~PictureList();
	int (*OnSetItem)(PictureList *This);
};

class PictureDraggableImage : public PictureControl
{
public:
	PictureDraggableImage(RECT Coords, HWND hWnd, LPDIRECTDRAWSURFACE7 surf, int flags);
	~PictureDraggableImage();
	LPDIRECTDRAWSURFACE7 surf;
	LPDIRECTDRAWSURFACE7 source;
	POINT FirstMouseCoords;
	int x; int y; RECT src;
	int dragged;
	int (*OnDblClick)(PictureDraggableImage *This);
	int InsertSurface(LPDIRECTDRAWSURFACE7 surface);
	int OnMouseLeftButtonDown(int x, int y);
	int OnMouseLeftButtonUp(int x, int y);
	int OnMouseMove(int x, int y);
	int OnMouseLeftButtonDblClick(int x, int y);
	int Update();
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
};

#define PICTIMG_LINKED 0x1
class PictureImage : public PictureControl
{
public:
	int *Multiplyer;
	POINT FirstMouseCoords;
	LPDIRECTDRAWSURFACE7 surf;
	LPDIRECTDRAWSURFACE7 source;
	POINT *CurrCoordinates;
	POINT StartingCoordinates;
	int dragged;
	DWORD FrameColor;
	PictureImage(RECT Coords, HWND hWnd, LPDIRECTDRAWSURFACE7 surf, DWORD FrameColor, int flags);
	~PictureImage();
	int SetLink(PictureImage *Img);
	int OnDrop(PictureControl *Control, int type);
	int OnMouseLeftButtonDown(int x, int y);
	int OnMouseLeftButtonUp(int x, int y);
	int OnMouseMove(int x, int y);
	int Update();
	int InsertSurface(LPDIRECTDRAWSURFACE7 surface);
	int ChangeMultiplyer(int M);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
};

#define PICTMATRIX_TRANSPARENT 0x1
#define PICTMATRIX_HIDEVALUES  0x2

class PictureMatrix : public PictureControl
{
public:
	int *Matrix;
	int ArrSize;
	int ShowValues;
	int FrameColor;
	int BackColor;
	int *XMatrix;
	BitmapFont *Font;
	LPDIRECTDRAWSURFACE7 DisabledImage;
	int (*OnXMatrixChanged)(PictureMatrix *This);
	PictureMatrix(RECT Coords, HWND hWnd, BitmapFont *Font, int FrameColor,
		int BackColor, int OnXMatrixChanged(PictureMatrix *This), int flags);
	~PictureMatrix();
	int SetDisabledImage(LPDIRECTDRAWSURFACE7 surf, int Copy);
	int SetMatrix(int *Values, int ArrSize);
	int ClearMatrix();
	int OnMouseLeftButtonDown(int x, int y);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
};

class PictureText : public PictureControl
{
public:
	PictureText(RECT Coords, HWND hWnd);
	int SetText(LPWSTR Text);
	int SetFont(BitmapFont *Font);
	int Redraw(LPDIRECTDRAWSURFACE7 dest);
	~PictureText();
private:
	LPWSTR Text;
	BitmapFont *Font;
};

#endif